package cn.xenosp.server.module.dict.service.impl;

import cn.xenosp.server.common.tools.IdUtil;
import cn.xenosp.server.common.tools.ObjectConvert;
import cn.xenosp.server.module.dict.entity.SysDictData;
import cn.xenosp.server.module.dict.entity.SysDictDataVO;
import cn.xenosp.server.module.dict.mapper.SysDictDataMapper;
import cn.xenosp.server.module.dict.service.SysDictDataService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author TongHui
* @description 针对表【sys_dict_data(字典数据表)】的数据库操作Service实现
* @createDate 2024-10-20 19:58:54
*/
@Service
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData>
    implements SysDictDataService{

    @Override
    public List<SysDictData> getListByDictType(String type) {
        return list(
                new LambdaQueryWrapper<SysDictData>()
                        .eq(SysDictData::getDictType, type)
                        .orderByAsc(SysDictData::getSort)
        );
    }

    @Override
    public List<SysDictData> save(SysDictDataVO sysDictDataVO) {
        SysDictData dictData = new SysDictData();
        ObjectConvert.copyVoToEntity(sysDictDataVO,dictData);

        dictData.setId(IdUtil.getId());

        save(dictData);
        return getListByDictType(dictData.getDictType());
    }

    @Override
    public List<SysDictData> update(SysDictDataVO sysDictDataVO) {
        SysDictData dictData = new SysDictData();
        ObjectConvert.copyVoToEntity(sysDictDataVO,dictData);
        updateById(dictData);
        return getListByDictType(dictData.getDictType());
    }

    @Override
    public List<SysDictData> delete(SysDictDataVO sysDictDataVO) {
        SysDictData dictData = new SysDictData();
        ObjectConvert.copyVoToEntity(sysDictDataVO,dictData);
        removeById(dictData);
        return getListByDictType(dictData.getDictType());
    }
}




